package com.it.service.impl;

import com.it.mapper.ContainerMapper;
import com.it.pojo.Container;
import com.it.pojo.ContainerExample;
import com.it.service.ContainerService;
import com.it.util.CodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: zgc
 * @version: 1.0
 * @description:
 * @date: 2023/12/25 12:49
 */
@Service
@Transactional
public class ContainerServiceImpl implements ContainerService {

    @Autowired
    private ContainerMapper containerMapper;

    @Override
    public List<Container> findAll() {
        ContainerExample example = new ContainerExample();
        ContainerExample.Criteria criteria = example.createCriteria();
        criteria.andContainerDelEqualTo(0);
        return containerMapper.selectByExample(example);
    }

    @Override
    public Container getOneContainer(String containerid) {
        return containerMapper.selectByPrimaryKey(containerid);
    }

    @Override
    public int addContainer(Container container) {
        container.setContainerId(getPrimaryKey());
        container.setContainerCode(CodeUtils.getCodeByCountCT(Integer.parseInt(getPrimaryKey())));
        container.setContainerRealvolume(0);
        container.setContainerStatus(0);
        container.setContainerDel(0);
        return containerMapper.insertSelective(container);
    }


    public String getPrimaryKey(){
        ContainerExample example = new ContainerExample();
        List<Container> list = containerMapper.selectByExample(example);
        return list.size()+1+"";
    }

}
